#include <stdio.h>
#include <unistd.h>
#include "mpi.h"
#include "oom.h"

int
main(int argc, char **argv)
{
	int size, rank, ranks[2];
	// int newcomm_rank;
	// int newgroup_members[2];
	// int a, b;
	MPI_Group worldgroup;
	MPI_Comm newgroup;
	MPI_Comm newcomm;
	Comm *comm;
	// Group *group;
	
	MPI_Init(&argc, &argv);
	
	MPI_Comm_size(MPI_COMM_WORLD, &size);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);

	comm = OOM_comm_lookup(MPI_COMM_WORLD);
	printf("MPI_COMM_WORLD contexts: %d %d\n", comm->p2p_context,
		comm->coll_context);

	ranks[0] = 0;
	ranks[1] = 1;
	
	MPI_Comm_group(MPI_COMM_WORLD, &worldgroup);
	MPI_Group_incl(worldgroup, 2, ranks, &newgroup);
	MPI_Comm_create(MPI_COMM_WORLD, newgroup, &newcomm);

	if (newcomm != MPI_COMM_NULL)
	{
		comm = OOM_comm_lookup(newcomm);
		printf("newcomm contexts: %d %d\n", comm->p2p_context,
			comm->coll_context);
	}
	
	MPI_Comm_free(&newcomm);
	
	MPI_Comm_dup(MPI_COMM_WORLD, &newcomm);
	comm = OOM_comm_lookup(newcomm);
	printf("MPI_COMM_WORLD duplicate contexts: %d %d\n", comm->p2p_context,
		comm->coll_context);
		
	MPI_Finalize();
	return 0;
}

